package com.qzimp.fujiancuo.service;

import com.qzimp.fujiancuo.entity.dto.CuoDetailsDto;
import com.qzimp.fujiancuo.service.CuoService;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;

import static org.mockito.Mockito.when;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
@SpringBootTest
@AutoConfigureMockMvc
public class test2 {

    @Autowired
    private MockMvc mockMvc;

    @MockBean
    private CuoService cuoService;

    @Test
    public void testSelectById() throws Exception {
        Integer cuoId = 1;
        CuoDetailsDto cuoDetailsDto = new CuoDetailsDto();
        cuoDetailsDto.setCuoId(cuoId);
        cuoDetailsDto.setCuoName("土楼王承启楼");

        // 模拟 CuoService.getCuoDetailsByCuoId 返回结果
        when(cuoService.getCuoDetailsByCuoId(cuoId)).thenReturn(cuoDetailsDto);

        // 执行 GET 请求，验证返回的状态码和内容
        mockMvc.perform(get("/cuo/details/{cuoId}", cuoId))
                .andExpect(MockMvcResultMatchers.status().isOk())  // 确认状态码 200
                .andExpect(MockMvcResultMatchers.jsonPath("$.data.cuoId").value(cuoId))  // 确认返回的 cuoId
                .andExpect(MockMvcResultMatchers.jsonPath("$.data.cuoName").value("土楼王承启楼"));  // 确认返回的 cuoName
    }
}
